home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12596 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.7 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: routine for yesterday's date
  5. Date: Mon, 01 Apr 96 22:14:31 GMT
  6. Organization: none
  7. Message-ID: <828396871snz@genesis.demon.co.uk>
  8. References: <315c4d0f.19874776@ottnews.shl.com> <1996Mar30.043002.19054@sq.com>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <1996Mar30.043002.19054@sq.com> msb@sq.com "Mark Brader" writes:
  15.  
  16. >You might think to fix the first problem by adding the line:
  17. >
  18. >        x.tm_isdst = -1;
  19. >
  20. >at the top, effectively forcing mktime() to work by wall clock time.
  21. >Now you are asking for the same time yesterday, rather than the time 24
  22. >hours ago.  But this doesn't fix the problem -- in the case of a daylight
  23. >saving time transition, "the same time yesterday" might be ambiguous or
  24. >not exist.  In such a case a failure of mktime() is allowed (or perhaps
  25. >required, depending on how one interprets the standard).
  26.  
  27. IMHO mktime() can't fail simply because of this. It it failed because
  28. 02:30 doesn't exist on a day then it should equally fail for 25:00 which
  29. doesn't exist on any day. In the case of 02:30 2 hours 30 mins after
  30. midnight is a valid time that is always representable (if the start and end
  31. of the day are).
  32.  
  33. >The correct fix is to let the daylight saving time transition take its
  34. >effect by leaving tm_isdst alone, but to ask for the time 24 hours before
  35. >a time near noon today.  Even if that time is 11 am or 1 pm, it will still
  36. >be yesterday.  So the final version of the code is:
  37. >
  38. >        x.tm_day--;             /* back 1 day (well, 24 hours) */
  39. >        x.tm_hour = 12;         /* from some time between noon and 1 pm */
  40. >
  41. >                                /* and normalize */
  42. >        if (mktime (&x) == (time_t) -1) {
  43. >                fprintf (stderr, "mktime failed!!\n");
  44. >                exit(1);
  45. >        }
  46.  
  47. I could easily set up timezone information on my system to make the
  48. daylight saving time transition occur at noon creating the same problem
  49. as before (if it is a problem). You'd need to try at a second time in the
  50. day if the first fails, e.g. 8am and 4pm.
  51.  
  52. ...
  53.  
  54. >There is a terser version of the "final" code: replace the first two lines by
  55. >
  56. >        x.tm_hour = -12;        /* 12 hours before sometime between
  57. >                                 * midnight and 1 am this morning */
  58.  
  59. Would you say this could fail if I set a noon DST changeover time?
  60.  
  61. -- 
  62. -----------------------------------------
  63. Lawrence Kirby | fred@genesis.demon.co.uk
  64. Wilts, England | 70734.126@compuserve.com
  65. -----------------------------------------
  66.